new Vue({
    el: '.container',
    data: {
        limitNum: 3,
        showNum: 3,
        moreFlag: false,
        addressList: [],
        currentIndex: 0,
        shippingMethod: 1
    },
    mounted: function () {
        this.$nextTick(function () {
            this.getAddressList();
        });
    },
    /**
     * data数据发生改变，也会重新调用过滤器
     * @returns {T[]}
     */
    computed: {
        filterAddress: function () {
            return this.addressList.slice(0, this.showNum);
        }
    },
    methods: {
        getAddressList: function () {
            var _this = this;
            this.$http.get("data/address.json").then(function (response) {
                var res = response.data;
                if (res.status == "0") {
                    _this.addressList = res.result;
                }
            });
        },
        loadMore: function () {
            this.moreFlag = !this.moreFlag;
            if (this.moreFlag) {
                this.showNum = this.addressList.length;
            } else {
                this.showNum = this.limitNum;
            }

        },
        setDefault: function (addressId) {
            this.addressList.forEach(function (address, index) {
                if (address.addressId == addressId) {
                    address.isDefault = true;
                } else {
                    address.isDefault = false;
                }
            });
        }
    }
});
